package com.itheima.service.impl;

import com.itheima.domain.pojo.ClazzSize;
import com.itheima.domain.pojo.JobOption;
import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 员工职位人数统计
     *
     * @return
     */
    @Override
    public JobOption getEmpJobData() {
        List<Map<String, Object>> list = empMapper.getEmpJobData();

        List<Object> jobList = list.stream().map(mapList -> mapList.get("job")).toList();
        List<Object> dateList = list.stream().map(mapList -> mapList.get("count")).toList();

        return new JobOption(jobList, dateList);
    }

    /**
     * 员工性别人数统计
     *
     * @return
     */
    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.getEmpGenderData();
    }

    /**
     * 学生学历人数统计
     * @return
     */
    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.getStudentDegreeData();
    }

    /**
     * 学生班级人数统计
     * @return
     */
    @Override
    public ClazzSize getStudentCountData() {
        List<Map<String,Object>> list =studentMapper.getStudentCountData();
        List<Object> clazzList = list.stream().map(mapList -> mapList.get("clazz")).toList();
        List<Object> dataList = list.stream().map(mapList -> mapList.get("count")).toList();
        return new ClazzSize(clazzList,dataList);
    }
}
